package com.zhz.mall.common.annotation;


import com.zhz.mall.common.util.enums.EnumValueResolver;
import com.zhz.mall.common.constraints.StringContainsValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * 存在
 *
 * @author zhouhengzhe
 */
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@Repeatable(StringContains.List.class)
@Documented
@Constraint(validatedBy = StringContainsValidator.class)
public @interface StringContains {

    String message() default "{com.ygp.its.infrastructure.utils.validation.constraints.StringContains}";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    Class<? extends EnumValueResolver> scopeEnum() default EnumValueResolver.class;
    /**
     * 范围，如果存在以此优先
     * @return 范围
     */
    String[] scope() default {};

    /**
     * 正则表达式
     * scope 优先匹配，而后正则表达式
     *
     * @return 正则表达式
     */
    String scopeRegex() default "";

    @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
    @Retention(RUNTIME)
    @Documented
    @interface List {

        StringContains[] value();
    }
}
